import lejos.nxt.Motor;
import lejos.robotics.subsumption.Behavior;

/**
 * Shoot the ball if it's in range and we're facing the goal.
 *
 */
public class Shoot implements Behavior {
	// Supsumtion Supression logic
	private boolean suppressed = false;
	private int IROffset = 110;

	/* (non-Javadoc)
	 * @see lejos.robotics.subsumption.Behavior#action()
	 */
	public void action() {
		Motor.C.setSpeed(900);

		Motor.A.forward();
		Motor.B.forward();

		Motor.C.rotate(-120, false);

		Motor.C.rotate(120, false);

		BillManager.SetIsFacingGoal(false);
	}

	/* (non-Javadoc)
	 * @see lejos.robotics.subsumption.Behavior#suppress()
	 */
	public void suppress() {
		suppressed = true;
	}

	/* (non-Javadoc)
	 * @see lejos.robotics.subsumption.Behavior#takeControl()
	 */
	public boolean takeControl() {
		// Is the ball in front of the robot
		// Has the robot got the ball
		// Is the robot facing the correct direction
		if (hasBall() && BillManager.IsFacingGoal()) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * Do we have the ball?
	 * @return True if the ball is close, otherwise false.
	 */
	public boolean hasBall() {
		return ((BillManager.GetInfraredData() == 5) && (BillManager
				.GetInfraredSensor3Data() > IROffset));
	}

}
